local shenxing = fk.CreateSkill({
  name = "sj3__shenxing",
})

Fk:loadTranslationTable {
  ["sj3__shenxing"] = "慎行",
  [":sj3__shenxing"] = "出牌阶段每个牌数限一次，你可以将任意张牌当【无中生有】使用。",

  ["@sj3__shenxing-phase"] = "慎行",
  ["#sj3__shenxing"] = "慎行：你可以将任意张牌当【无中生有】使用",

  ["$sj3__shenxing1"] = "审时度势，乃容万变。",
  ["$sj3__shenxing2"] = "此需斟酌一二。",
}

shenxing.sj3__zhongliu_type = Player.HistoryPhase

shenxing:addEffect("active", {
  prompt = "#sj3__shenxing",
  can_use = function(self, player)
    return player.phase == Player.Play
  end,
  card_filter = function(self, player, to_select, selected)
    return table.contains(player:getHandlyIds(), to_select) or table.contains(player:getCardIds("e"), to_select)
  end,
  target_filter = Util.FalseFunc,
  feasible = function(self, player, selected, selected_cards, card)
    return #selected_cards > 0 and not table.contains(player:getTableMark("sj3__shenxing-phase"), #selected_cards)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:addTableMark(player, "sj3__shenxing-phase", #effect.cards)
    room:setPlayerMark(player, "@sj3__shenxing-phase", table.concat(player:getTableMark("sj3__shenxing-phase"), "/"))
    local card = Fk:cloneCard("ex_nihilo")
    card:addSubcards(effect.cards)
    card.skillName = shenxing.name
    room:useCard {
      from = player,
      card = card,
      tos = { player },
    }
  end,
})

shenxing:addEffect(fk.AfterSkillEffect, {
  can_refresh = function(self, event, target, player, data)
    return player:getMark("@sj3__shenxing-phase") ~= 0 and
        player:usedSkillTimes(shenxing.name, Player.HistoryPhase) == 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "sj3__shenxing-phase", 0)
    player.room:setPlayerMark(player, "@sj3__shenxing-phase", 0)
    --十分拉跨的重置
  end,
})


return shenxing
